﻿using LoveEat.API.Write.Applications.Commands.Goods;
using LoveEat.Domain.Goods;
using LoveEat.ErrorCode;
using LoveEat.Infrastructure.Interfaces;
using MediatR;
using Microsoft.AspNetCore.Server.HttpSys;
using Microsoft.VisualBasic;

namespace LoveEat.API.Write.Applications.CommandHandlers.Goods
{
    public class UpdateGoodsCommandHandler : IRequestHandler<UpdateGoodsCommand, APIResult<int>>
    {
        public readonly IBaseRespository<GoodsModel> goodsRep;

        public UpdateGoodsCommandHandler(IBaseRespository<GoodsModel> goodsRep)
        {
            this.goodsRep = goodsRep;
        }

        public async Task<APIResult<int>> Handle(UpdateGoodsCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result=new APIResult<int>();
            result.Code=APIResultCode.修改成功;
            result.Message=APIResultCode.修改成功.ToString();

            var res=goodsRep.GetAll().FirstOrDefault(x=>x.GoodsId==request.GoodsId);
            res.GoodsNameId=request.GoodsNameId;
            res.Production = request.Production;
            res.LifeDay=request.LifeDay;
            res.Pronumber=request.Pronumber;
            res.ProCommand=request.ProCommand;
            res.Path=request.Path;
            res.Information=request.Information;
            res.UpdateName=request.UpdateName;
            await goodsRep.UpdateAsync(res);



            return await Task.FromResult(result);
        }
    }
}
